package com.hnist.das.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.hnist.das.pojo.User;
import com.hnist.das.service.IUserService;

@Controller
@RequestMapping(value = "/account")
public class AccountController {
	@Resource
	private IUserService userService;

	@RequestMapping(value = "/login", method = { RequestMethod.GET })
	public String login() {
		return "account/login";
	}

	@RequestMapping(value = "/login", method = { RequestMethod.POST })
	public ModelAndView index(User user, HttpServletRequest request, HttpServletResponse response,
			HttpSession httpSession) {
		// user.setUser_name(user_name);
		// User user = this.userService.checkUserExits(user);
		ModelAndView modelAndView = new ModelAndView();
		User userResult = this.userService.checkUserExits(user);
		if (null != userResult) {
			httpSession.setAttribute("user", userResult);
			modelAndView.setViewName("redirect:/index");
		} else {
			System.out.println("wrong.....");
		}
		return modelAndView;
	}
}
